package org.jeecg.chase.common.script.service;

import org.jeecg.chase.common.base.data.BaseQuery;
import org.jeecg.chase.common.engine.service.AbstractCommonDataService;
import org.jeecg.chase.common.script.dao.CommonDataDao;
import org.jeecg.chase.common.supper.process.CommonProcess;
import org.jeecg.chase.common.supper.query.ListQueryContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author leikai
 * @version 1.0
 * @description: 通用service
 * @date 2021/07/23/0023 15:59
 */
@Service
@Transactional
public class CommonDataService extends AbstractCommonDataService {

    @Autowired
    private CommonDataDao commonDataDao;

    public Object get(BaseQuery baseQuery) {
//        Class<?> queryClass = baseQuery.getClass();
//        Class<?> boClass = DetailQueryContainer.getBoClass(queryClass);
//        List<Object> objList = commonDataDao.getList(baseQuery, boClass);

        List<CommonProcess> querybeforeProcessList = ListQueryContainer.getQueryBeforeProcessList(baseQuery.getModelId());
        processService.process(baseQuery, querybeforeProcessList);
        
        Class<?> resultClass = getResultClass(baseQuery);
        Object obj = commonDataDao.get(baseQuery, resultClass);
        //对查询结果进行后置处理
        List<CommonProcess> resultAfterProcessList = ListQueryContainer.getResultAfterProcessList(baseQuery.getModelId());
        processService.process(obj, resultAfterProcessList);
        return obj;
    }
}
